/*
 * Copyright 2010 Kevin L'Huillier <klhuillier@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.lhuillier.pwsafe.model;


import static org.lhuillier.pwsafe.model.PrefStorageType.*;


/**
 * Known types of preferences stored as simple strings.
 * <p>
 * Only two are stored in the database: {@link #DEFAULT_USERNAME} and
 * {@link #DEFAULT_AUTOTYPE_STRING}.
 */
public enum StringPrefType {
    CURRENT_BACKUP("", APPLICATION),
    /**
     * Name of the currently-opened password database.
     */
    CURRENT_FILE("", APPLICATION),
    LAST_VIEW("tree", APPLICATION),
    /**
     * If {@link BooleanPrefType#USE_DEFAULT_USER} is true, this value will
     * be used as the default username.
     */
    DEFAULT_USERNAME("", DATABASE),
    TREE_FONT("", APPLICATION),
    BACKUP_PREFIX_VALUE("", APPLICATION),
    BACKUP_DIR("", APPLICATION),
    ALT_BROWSER("", APPLICATION),
    LIST_COLUMNS("", APPLICATION),
    COLUMN_WIDTHS("", APPLICATION),
    /**
     * The default string to autotype for an entry. This can be overridden
     * for an individual entry. Special escape values can be used, each prefixed
     * with a backslash such as \t for tab, \p for password, or \ u for
     * username (without the space... that escape sequence is special in Java
     * and can't normally be typed)
     */
    DEFAULT_AUTOTYPE_STRING("", DATABASE),
    ALT_BROWSER_CMD_LINE_PARAMS("", APPLICATION),
    MAIN_TOOL_BAR_BUTTONS("", APPLICATION),
    PASSWORD_FONT("", APPLICATION),
    TREE_LIST_SAMPLE_TEXT("AaBbYyZz 0O1IlL", APPLICATION),
    PSWD_SAMPLE_TEXT("AaBbYyZz 0O1IlL", APPLICATION),
    LAST_USED_KEYBOARD("", APPLICATION),
    VKEYBOARD_FONT_NAME("", APPLICATION),
    VK_SAMPLE_TEXT("AaBbYyZz 0O1IlL", APPLICATION),
    ALT_NOTES_EDITOR("", APPLICATION);

    private final String defaultValue;
    private final PrefStorageType storageType;

    StringPrefType(String defaultValue, PrefStorageType storageType) {
        this.defaultValue = defaultValue;
        this.storageType = storageType;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public PrefStorageType getStorageType() {
        return storageType;
    }

    /**
     * @param id the 0-based ID
     * @return the constant or null
     */
    public static StringPrefType forId(int id) {
        StringPrefType[] values = values();
        if (id < 0 || id >= values.length) {
            return null;
        }
        return values[id];
    }
}
